//
//  RadioListViewController.m
//  宝宝儿歌
//
//  Created by student on 16/4/19.
//  Copyright © 2016年 baobaoerge. All rights reserved.
//

#import "RadioListViewController.h"

#import "RadioDetailViewController.h"
#import "RadioModel.h"
#import "RadioGroupModel.h"

#import "BlurImageView.h"

#import "ModelSingleton.h"
#import "ModelGroupListInfo.h"
#import <UIImageView+WebCache.h>



@interface RadioListViewController ()

@property (nonatomic, strong)NSArray *list;

@end

@implementation RadioListViewController

- (void)loadView
{
    [super loadView];

}

- (void)viewDidLoad {

    BlurImageView *imageView = [[BlurImageView alloc] initWithFrame:self.view.bounds];
    [imageView refreshBackgroundBlurView];
    [self.view addSubview:imageView];
    NSString *str = @"http://www.ximalaya.com/dq/kid-%E5%84%BF%E6%AD%8C%E5%A4%A7%E5%85%A8/";
//    NSString *str1 = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [ModelGroupListInfo modelGroupListInfo:str successBlok:^(NSArray *imgList) {
        self.list = imgList;
        [self.tableView reloadData];
    } failBlok:^(NSError *error) {
        
    }];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"radioListCell" forIndexPath:indexPath];
    NSDictionary *dict =self.list[indexPath.row];
    RadioGroupModel *radioGroupModel = [RadioGroupModel radioGroupModelWithDictionary:dict];
    
    
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:radioGroupModel.radioGroupImage] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    cell.textLabel.text = radioGroupModel.radioGroupTitle;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dict = self.list[indexPath.row];
    RadioGroupModel *radioGroupModel = [RadioGroupModel radioGroupModelWithDictionary:dict];
    RadioDetailViewController *rdVC = [[RadioDetailViewController alloc]init];
    rdVC.radioModelLink = radioGroupModel.radioGroupLink;
    rdVC.radioImage = radioGroupModel.radioGroupImage;
    [self.navigationController pushViewController:rdVC animated:YES];
}



@end
